import axios from 'axios'
import { Logger } from './Logger';

export class HttpUtil {

    public static request(url: string = "http://212.64.108.20:8888/info", data: object = {}, callback: Function = () => { }) {
        if(url == ""){
            callback && callback(null)
            return;
        }
        Logger.log("HttpUtil.request",url, data)
        axios({
            method: 'post',
            url: url,
            headers: {
                'Content-Type': 'text/plain;charset=UTF-8'
            },
            data: data
        })
            .then(function (response) {
                // Logger.log("HttpUtil request", response);
                callback && callback(response)
            })
            .catch(function (error) {
                Logger.warn("HttpUtil error",url,data, error);
                callback && callback(error)
            });
    }


}